package com.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;

import com.dao.CommonDAO;
import com.dao.SysuserDAO;
import com.model.Menuinfo;
import com.model.Notice;
import com.model.Sysuser;
import com.model.Userrole;
import com.opensymphony.xwork2.ActionSupport;
import com.util.Info;
import com.util.Pagination;

public class roleAction extends ActionSupport
{
	private Integer id;
	private String utype;
	private String role;
	private int index=1;
	String no;
	String suc;
	private CommonDAO commonDAO;
	private String[] roles;
	

	public String[] getRoles() {
		return roles;
	}

	public void setRoles(String[] roles) {
		this.roles = roles;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUtype() {
		return utype;
	}

	public void setUtype(String utype) {
		this.utype = utype;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public String getSuc() {
		return suc;
	}

	public void setSuc(String suc) {
		this.suc = suc;
	}

	public CommonDAO getCommonDAO() {
		return commonDAO;
	}

	public void setCommonDAO(CommonDAO commonDAO) {
		this.commonDAO = commonDAO;
	}

	//权限设置
	public String roleEdit(){
		
			ArrayList<Userrole> urlist = (ArrayList<Userrole>)commonDAO.findByHql(" from Userrole where utype='"+utype+"'");
			for(Userrole ur:urlist){
				commonDAO.delete(ur.getId(), "Userrole");
			}
			Userrole u = new Userrole();
			for(int i=0;i<roles.length;i++){
				u.setRole(roles[i]);
				u.setUtype(utype);
				commonDAO.save(u);
			}
		    suc="";
			return "success";
	}
	
	
	
}
